﻿using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Communication.Serial {
    /// <summary>
    /// 串口参数
    /// </summary>
    public class SerialParam {
        #region 字段
        private string portName;
        private int baudRate;
        private int dataBits;
        private StopBits stopBits;
        private Parity paritys;
        private int readTimeout;
        private int writeTimeout;
        #endregion

        #region 构造函数
        /// <summary>
        /// 构造函数
        /// </summary>
        public SerialParam() {
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="portName">端口号</param>
        /// <param name="baudRate">波特率</param>
        /// <param name="dataBits">数据位</param>
        /// <param name="stopBits">停止位</param>
        /// <param name="paritys">效验位</param>
        public SerialParam(string portName,int baudRate,int dataBits,StopBits stopBits,Parity paritys) {
            this.portName = portName;
            this.baudRate = baudRate;
            this.dataBits = dataBits;
            this.stopBits = stopBits;
            this.paritys = paritys;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="portName">端口号</param>
        /// <param name="baudRate">波特率</param>
        /// <param name="dataBits">数据位</param>
        /// <param name="stopBits">停止位</param>
        /// <param name="paritys">效验位</param>
        /// <param name="readTimeout">读超时时间</param>
        /// <param name="writeTimeout">写超时时间</param>
        public SerialParam(string portName,int baudRate,int dataBits,StopBits stopBits,Parity paritys,int readTimeout,int writeTimeout) {
            this.portName = portName;
            this.baudRate = baudRate;
            this.dataBits = dataBits;
            this.stopBits = stopBits;
            this.paritys = paritys;
            this.readTimeout = readTimeout;
            this.writeTimeout = writeTimeout;
        }
        #endregion

        #region 属性
        /// <summary>
        /// 端口号
        /// </summary>
        public string PortName {
            get {
                return portName;
            }
            set {
                portName = value;
            }
        }

        /// <summary>
        /// 波特率
        /// </summary>
        public int BaudRate {
            get {
                return baudRate;
            }
            set {
                baudRate = value;
            }
        }

        /// <summary>
        /// 数据位
        /// </summary>
        public int DataBits {
            get {
                return dataBits;
            }
            set {
                dataBits = value;
            }
        }

        /// <summary>
        /// 停止位
        /// </summary>
        public StopBits StopBit {
            get {
                return stopBits;
            }
            set {
                stopBits = value;
            }
        }

        /// <summary>
        /// 效验位
        /// </summary>
        public Parity Paritys {
            get {
                return paritys;
            }
            set {
                paritys = value;
            }
        }

        /// <summary>
        /// 读超时时间
        /// </summary>
        public int ReadTimeout {
            get {
                return readTimeout;
            }
            set {
                readTimeout = value;
            }
        }

        /// <summary>
        /// 写超时时间
        /// </summary>
        public int WriteTimeout {
            get {
                return writeTimeout;
            }
            set {
                writeTimeout = value;
            }
        }
        #endregion
    }
}
